package com.jsoft.jsofted.platform.controller;

import com.jsoft.jsofted.framework.annotation.JwtToken;
import com.jsoft.jsofted.framework.controller.DataController;
import com.jsoft.jsofted.platform.entity.MenuEntity;
import com.jsoft.jsofted.framework.service.CocService;
import com.jsoft.jsofted.platform.service.MenuService;
import com.jsoft.jsofted.framework.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;

@RestController
@RequestMapping("/jsofted/menu")
public class MenuController extends DataController<MenuEntity> {

    @Autowired
    private MenuService menuService;

    @Override
    public CocService<MenuEntity> cocService() {
        return menuService;
    }

    @JwtToken
    @RequestMapping("/tree")
    public ResponseModel tree(@RequestBody(required = false) LinkedHashMap queryParams) {
        List tree = menuService.queryTree(queryParams);

        return ResponseModel.makeSuccess(null, tree);
    }

    @JwtToken
    @RequestMapping("/sort")
    public ResponseModel sort(@RequestBody(required = false) LinkedHashMap sortParams) {
        return this._sort(sortParams);
    }
}
